package com.example.demo.netty.myprotocol;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * <内容说明>
 *
 * @author yu.guangqi
 * created on 2019/11/8 16:08
 */
public class MyByteToLongDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("MyByteToLongDecoder decode invoked!");

        System.out.println(in.readableBytes());//可读字节数

        if (in.readableBytes() >= 8) {
            long msg = in.readLong();
            out.add(msg);
        }
    }
}
